home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacGames Sampler
/
PHT MacGames Bundle.iso
/
MacSource Folder
/
Samples from the CD
/
C and C++
/
Think Power 1.0B4
/
Extensions Src
/
Rot13.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-07
|
1KB
|
62 lines
// Rot13.c - Written by Stefan Arentz, August 1993
#include "THINK Power Extensions.h"
void Rot13(char *textPtr, long textLength);
pascal void main(TPCallbackBlock *theCallbacks, WindowPtr theWindow) {
Handle theText, theResult;
long textLength;
long selStart, selEnd, firstChar;
theText = theCallbacks->GetWindowContents(theWindow);
if (theText) {
textLength = GetHandleSize(theText);
theCallbacks->GetSelection(&selStart, &selEnd, &firstChar);
if (selStart == selEnd) {
selStart = 0;
selEnd = textLength;
}
if (textLength){
theResult = NewHandle(selEnd - selStart);
if (theResult) {
BlockMove(*theText + selStart, *theResult, selEnd - selStart);
Rot13(*theResult, selEnd - selStart);
(void) theCallbacks->Paste(theResult);
theCallbacks->SetSelection(selStart, selEnd, selStart);
DisposeHandle(theResult);
}
}
}
}
void Rot13(char *textPtr, long textLength) {
while (textLength--) {
if (*textPtr >= 'A' && *textPtr <= 'Z') {
*textPtr = ((*textPtr - 'A' + 13) % 26) + 'A';
} else if (*textPtr >= 'a' && *textPtr <= 'z') {
*textPtr = ((*textPtr - 'a' + 13) % 26) + 'a';
}
textPtr++;
}
}